package com.hxm.appGenealogy.Function;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxm.appGenealogy.config.queryVo.QueryWrapperVO;
import com.hxm.appGenealogy.entity.Dynamic;
import com.hxm.appGenealogy.mapper.DynamicMapper;
import org.apache.catalina.LifecycleState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 发表文章基础模块;
 */
@Component
public class DynamicFunction {

    @Autowired
    private DynamicMapper dynamicMapper;

    public Dynamic selectByid(Long id) {
        return dynamicMapper.selectById(id);
    }


    public Dynamic insertDynamic(Dynamic dynamic){
        dynamicMapper.insert(dynamic);
        return dynamic;
    }

    public void  dedl(Dynamic dynamic){
        dynamicMapper.deleteById(dynamic.getId());
    }

    public List<Dynamic> selectGetListQuery(String query){
        QueryWrapper<Dynamic> queryWrapper = QueryWrapperVO.getQueryWrapper(query);
        List<Dynamic> dynamics = dynamicMapper.selectList(queryWrapper);
        return dynamics;
    }

    public Dynamic slectGetOneQuery(String query){
        QueryWrapper<Dynamic> queryWrapper = QueryWrapperVO.getQueryWrapper(query);
        Dynamic dynamics = dynamicMapper.selectOne(queryWrapper);
        return dynamics;
    }
    /**
     * 分页查询;
     */
    public Page selectPage(Page page,String query){
        QueryWrapper<Dynamic> queryWrapper = QueryWrapperVO.getQueryWrapper(query);
        Page page1 = dynamicMapper.selectPage(page, queryWrapper);
        return page1;
    }

    /**
     * 根据id修改数据;
     */
    public void  updateByid(Dynamic dynamic){
        dynamicMapper.updateById(dynamic);
    }
}
